<?php
/**
 * Created by PhpStorm.
 * User: LOPO
 * Date: 2020/4/15
 * Time: 14:17
 */
namespace App\HttpController\Api;
use App\Lib\Redis\Redis;
use EasySwoole\Component\Di;
use EasySwoole\Mysqli\Config;
use EasySwoole\Mysqli\Client;
use EasySwoole\EasySwoole\Config as Configs;

class Index extends Base
{

    public function video(){
        $data =[
            'id'=>2,
            'name'=>'lopo'
        ];
        return $this->writeJson(200,'OK',$data);
    }

    public function getVideo(){
        $config=Configs::getInstance()->getConf('MYSQL');
        $conf = new Config($config);
        $db = new Client($conf);
        $db->queryBuilder()->get('video');//获取一个表的数据
        $data = $db->execBuilder();
        return $this->writeJson(200,  'ok',$data);
    }

    public function getRedis(){
//        $redis = new \Redis();
//        $redis->connect("127.0.0.1",6379,5);
//        $redis->set("lopo123",90);
//        $result = Redis::getInstance()->get("lopo123");
        $result = Di::getInstance()->get("REDIS")->get("lopo123");
        return $this->writeJson(200,  'ok',$result);
    }

    public function yaconf(){
        $result = \Yaconf::get('redis');
        return $this->writeJson(200,  'ok',$result);

    }

    public function pub(){
        $params = $this->request()->getRequestParam();
        Di::getInstance()->get("REDIS")->rPush('imooc_list_test',$params['f']);

    }
}